package com.alibaba.cola.demo.service.impl;

import com.alibaba.cola.core.command.CommandBusI;
import com.alibaba.cola.demo.common.Result;
import com.alibaba.cola.demo.domain.Product;
import com.alibaba.cola.demo.domain.ProductExample;
import com.alibaba.cola.demo.dto.ProductDto;
import com.alibaba.cola.demo.dto.ProductQry;
import com.alibaba.cola.demo.mapper.ProductMapper;
import com.alibaba.cola.demo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private CommandBusI commandBus;

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> listAll() {
        ProductExample example = new ProductExample();
        List<Product> list = productMapper.selectByExample(example);
        return list;
    }

    @Override
    public Result<List<ProductDto>> findByQry(ProductQry qry) {
        return (Result<List<ProductDto>>) commandBus.send(qry);
    }
}
